package web_programing.review.Tcp;

import java.io.*;
import java.net.Socket;
import java.util.Scanner;

/**
 * @author haomin
 * @date 2022/09/27 18:33
 **/
public class 长连接子输入Client {
    public static void main(String[] args) throws IOException {
        Socket socket = new Socket("127.0.0.1", 8080);
        Scanner systemInSc = new Scanner(System.in);

        while (systemInSc.hasNextLine()){
            String w = systemInSc.nextLine();

            InputStream is = socket.getInputStream();
            Scanner scanner = new Scanner(is, "utf-8");

            OutputStream os = socket.getOutputStream();
            OutputStreamWriter writer = new OutputStreamWriter(os, "utf-8");
            PrintWriter printWriter = new PrintWriter(writer);

            // 发送请求
            printWriter.printf("我是Java19班的\r\n%s\r\n", w);
            printWriter.flush();

            // 读取响应
            String header = scanner.nextLine();
            String chineseWord = scanner.nextLine();
            System.out.println("响应结果：" + chineseWord);
        }

        socket.close();
    }
}